package com.learn.mybatis.controller

import com.learn.mybatis.entity.StudentEntity
import com.learn.mybatis.mapper.StudentMapper
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import javax.annotation.Resource

/**
 *
 * @author zhub
 * @create 2018/8/11 17:02
 * @email zhub1@elab-plus.com
 **/
@RestController
@RequestMapping("/student")
class StudentController {

    @Resource
    lateinit var studentMapper: StudentMapper

    @RequestMapping("/list", produces = ["application/json;charset=UTF-8"])
    fun getStudentList(): List<StudentEntity> {
        return studentMapper.getStudentList()
    }

    @RequestMapping("/insert")
    fun insert(@RequestBody studentEntity: StudentEntity): String {
        studentMapper.insert(studentEntity.name, studentEntity.age)
        return "success"
    }

}